#!/usr/bin/python
#coding=utf-8

from xml.etree import ElementTree as ET
import urllib  
import re

tree = ET.parse('collection_movie_watched_back.xml')

root = tree.getroot()
print root
#for elem in root.getiterator():
#    print elem.tag, elem.attrib

id_collect = root.find('{http://www.w3.org/2005/Atom}title')
print id_collect.text

items = root.findall('{http://www.w3.org/2005/Atom}entry/{http://www.douban.com/xmlns/}subject')
for elem in items:
    title = elem.find('{http://www.w3.org/2005/Atom}title').text
    title_remix = re.sub(r"(\/|\\|\:|\*|\"|\<|\>|\|)", "_", title)
    path = r".\list\\" + title_remix + ".jpg"
    f = file(path,"wb")
    links = elem.findall('{http://www.w3.org/2005/Atom}link')
    for link in links:
        if link.get('rel')=='image':
            url = link.get('href').replace('spic','lpic')
            data = urllib.urlopen(url).read()
            f.write(data)  
            print url
    f.close
print "done!!!"





